package service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import dao.MemberDAO;
import dto.AdminDTO;
import dto.CompanyDTO;
import dto.ListCompanyPageDTO;
import dto.ListMemberPageDTO;
import dto.ListSalePageDTO;
import dto.MemberDTO;
import dto.PagingDTO;
import dto.SaleListDTO;

public class MemberService {
	private MemberDAO dao;
	public MemberService(MemberDAO dao){
		this.dao = dao;
	}
	//동으로 주소찾기
	public ArrayList addressSearch(String dong) {
		
		return dao.addressSearch(dong);
	}
	//id로 회원조회
	public MemberDTO getMemberById(String id)  throws SQLException{
		
		return dao.selectMemberById(id);
	}
	//id로 기업조회
	public CompanyDTO getCompanyById(String id) throws SQLException{
		
		return  dao.selectCompanyById(id);
	}
	//id로 관리자 조회
	public AdminDTO getAdminById(String id) throws SQLException{
		 
		return dao.selectAdminById(id);
	}
	//회원삭제
	public void removeMemberByid(String id) throws SQLException {
		int cnt = dao.deleteMemberById(id);
		System.out.println(cnt+"개의 행이 삭제되었습니다.");
		
	}
	//기업삭제
	public void removeCompanyByid(String id) {
		int cnt = dao.deleteCompanyById(id);
		System.out.println(cnt+"개의 행이 삭제되었습니다.");
		
	}
	//관리자 삭제
	public void removeAdminByid(String id) {
		int cnt = dao.deleteAdminById(id);
		System.out.println(cnt+"개의 행이 삭제되었습니다.");
		
	}
	//회원가입
	public void registerMember(MemberDTO mdto) {
		dao.registerMember(mdto);
		
	}
	//기업가입
	public void registerCompany(CompanyDTO cdto) {
		dao.registerCompany(cdto); 
		
	}
	//회원정보수정
	public void modifyMember(MemberDTO mdto) {
		dao.modifyMember(mdto);
		
	}
	//기업정보수정
	public void modifyCompany(CompanyDTO cdto) {
		dao.modifyCompany(cdto);
		
	}
	//관리자 정보 수정
	public void modifyAdmin(AdminDTO adto) {
		dao.modifyAdmin(adto);
		
	}
	//모든 회원조회
	public ArrayList<MemberDTO> getAllMember() {
		return dao.getAllMember();
	}
	//모든 기업조회
	public ArrayList<CompanyDTO> getAllCompany() {
		return dao.getAllCompany();
	}
	
	//관리자 모드 - 강제 탈퇴기능
	public void adminMemberDelete(MemberDTO mdto) {
		dao.adminMemberDelete(mdto);
	}
	public void adminCompanyDelete(CompanyDTO cdto) {
		dao.adminCompanyDelete(cdto);
	}
	//아이디 비밀번호 조회
	public String memberIdSearchResult(MemberDTO mdto) {
		 
		return dao.memberIdSearchResult(mdto);
	}
	public String memberPasswordSearchResult(MemberDTO mdto) {
		
		return dao.memberPasswordSearchResult(mdto);
	}
	public String companyIdSearchResult(CompanyDTO cdto) {
		return dao.companyIdSearchResult(cdto);
	}
	public String companyPasswordSearchResult(CompanyDTO cdto) {
		return dao.companyPasswordSearchResult(cdto);
	}
	public String adminIdSearchResult(AdminDTO adto) {
		return dao.adminIdSearchResult(adto);
	}
	public String adminPasswordSearchResult(AdminDTO adto) {
		return dao.adminPasswordSearchResult(adto);
	}
	//회원 탈퇴 취소
	public void adminMemberReceive(MemberDTO mdto) {
		dao.adminMemberReceive(mdto);
		
	}
	public void adminCompanyReceive(CompanyDTO cdto) {
		dao.adminCompanyReceive(cdto);
		
	}
	
	//paging 후 회원 검색
	public ListMemberPageDTO getMemberListByPage(int page) {
		 
		ListMemberPageDTO listMemberPageDTO = null;
	 
		ArrayList<MemberDTO> memberList = dao.selectMemberListByPaging(page);
		 
		int total = dao.selectMemberTotalContent();
		 
		PagingDTO pdto = new PagingDTO(total, page);
		 
		listMemberPageDTO = new ListMemberPageDTO(memberList ,pdto);
		return listMemberPageDTO;
		 
	}
	//paging 후 기업 검색
	public ListCompanyPageDTO getCompanyListByPage(int page) {
		ListCompanyPageDTO listCompanyPageDTO = null;
		ArrayList<CompanyDTO> companyList = dao.selectCompanyListByPaging(page);
		 
		int total = dao.selectCompanyTotalContent();
		PagingDTO pdto = new PagingDTO(total, page);
		 
		listCompanyPageDTO = new ListCompanyPageDTO(companyList ,pdto);
		return listCompanyPageDTO;
	}
	public void updateCredit(String id, String credit) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("id", id);
		map.put("credit", credit);
		dao.updateCredit(map);
	}
	public void updateCreditCompany(String id, String credit) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("id", id);
		map.put("credit", credit);
		dao.updateCreditCompany(map);
		
	}
	public void memberPointAdd(int mileage, String id) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("mileage", String.valueOf(mileage));
		map.put("id", id);
		dao.memberPointAdd(map);
	}
	public void companyPointAdd(int mileage, String id) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("mileage", String.valueOf(mileage));
		map.put("id", id);
		dao.companyPointAdd(map);
		
	}
	 
	 

}
